import org.jcodec.api.FrameGrab;
import org.jcodec.api.JCodecException;
import org.jcodec.api.MediaInfo;
import org.jcodec.api.SequenceEncoder;
import org.jcodec.common.Demuxer;
import org.jcodec.common.DemuxerTrack;
import org.jcodec.common.io.NIOUtils;
import org.jcodec.common.io.SeekableByteChannel;
import org.jcodec.common.model.ColorSpace;
import org.jcodec.common.model.Picture;
import org.jcodec.common.model.Size;
import org.jcodec.containers.mp4.demuxer.MP4Demuxer;
import org.jcodec.containers.mp4.demuxer.MP4DemuxerTrack;

import java.io.*;

public class VideoSizeExample {
    //    public static void main(String[] args) {
//        String videoPath = "C:\\Users\\Shmily_0219\\Downloads\\20230217134718.mov";
//
//        try {
//            // 打开视频文件
//            IContainer container = IContainer.make();
//            if (container.open(videoPath, IContainer.Type.READ, null) < 0) {
//                throw new RuntimeException("Failed to open video file.");
//            }
//
//            // 获取视频流
//            IStream videoStream = null;
//            for (int i = 0; i < container.getNumStreams(); i++) {
//                IStream stream = container.getStream(i);
//                if (stream.getStreamCoder().getCodecType() == com.xuggle.xuggler.ICodec.Type.CODEC_TYPE_VIDEO) {
//                    videoStream = stream;
//                    break;
//                }
//            }
//
//            if (videoStream == null) {
//                throw new RuntimeException("Video stream not found in the container.");
//            }
//
//            // 获取视频尺寸
//            int width = videoStream.getStreamCoder().getWidth();
//            int height = videoStream.getStreamCoder().getHeight();
//
//            System.out.println("Video Width: " + width);
//            System.out.println("Video Height: " + height);
//
//            // 关闭容器
//            container.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
    public static void main(String[] args) throws IOException, JCodecException {
        File file = new File("C:\\Users\\Shmily_0219\\Downloads\\as.mp4");
        FrameGrab grab = FrameGrab.createFrameGrab(NIOUtils.readableChannel(file));
        Picture picture = grab.getNativeFrame();
        System.out.println("Video Width: " + picture.getWidth());
        System.out.println("Video Height: " + picture.getHeight());


    }

}
